{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fbfbca28",
   "metadata": {},
   "source": [
    "# Introduction to Sets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2f844cf",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efe5bdfd",
   "metadata": {},
   "source": [
    "This notebook was created by [Jupyter AI](https://github.com/jupyterlab/jupyter-ai) with the following prompt:\n",
    "\n",
    "> /generate A Python notebook that teaches how to use sets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0fe6e00",
   "metadata": {},
   "source": [
    "This Jupyter notebook provides a comprehensive guide on how to use sets in Python. It covers various topics such as creating a set, adding and removing elements from a set, checking if an element is in a set, and performing set operations. The notebook's description emphasizes its purpose to teach users about sets, and the prompt highlights the main topic of the notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18feddd5",
   "metadata": {},
   "source": [
    "## Adding Elements to a Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0235ac93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "# Improving the code\n",
    "my_set = {1, 2, 3}\n",
    "print(my_set)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bc0d88e",
   "metadata": {},
   "source": [
    "## Removing Elements from a Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "686d68bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_set = {1, 2, 3, 4, 5}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f99040de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original set: {1, 2, 3, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "print(\"Original set:\", my_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fcb1e029",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "After removing '3': {1, 2, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "my_set.remove(3)\n",
    "print(\"After removing '3':\", my_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ff34fdc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "After discarding '5': {1, 2, 4}\n"
     ]
    }
   ],
   "source": [
    "my_set.discard(5)\n",
    "print(\"After discarding '5':\", my_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d3cbcc3a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Removed element: 1\n",
      "After popping an element: {2, 4}\n"
     ]
    }
   ],
   "source": [
    "removed_element = my_set.pop()\n",
    "print(\"Removed element:\", removed_element)\n",
    "print(\"After popping an element:\", my_set)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df136c9e",
   "metadata": {},
   "source": [
    "## Checking if an Element is in a Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "13bda382",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Checking if an Element is in a Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3a941f10",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a set\n",
    "my_set = {1, 2, 3, 4, 5}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e923bacd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 is in the set.\n"
     ]
    }
   ],
   "source": [
    "# Check if an element is in the set\n",
    "element = 3\n",
    "if element in my_set:\n",
    "    print(f\"{element} is in the set.\")\n",
    "else:\n",
    "    print(f\"{element} is not in the set.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f3115ce",
   "metadata": {},
   "source": [
    "## Set Operations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b7447c2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "set1 = {1, 2, 3, 4, 5}\n",
    "set2 = {4, 5, 6, 7, 8}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6f092687",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Union of set1 and set2: {1, 2, 3, 4, 5, 6, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "union_set = set1 | set2\n",
    "print(\"Union of set1 and set2:\", union_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b9854615",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intersection of set1 and set2: {4, 5}\n"
     ]
    }
   ],
   "source": [
    "intersection_set = set1 & set2\n",
    "print(\"Intersection of set1 and set2:\", intersection_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f01a181c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Difference between set1 and set2: {1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "difference_set = set1 - set2\n",
    "print(\"Difference between set1 and set2:\", difference_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "87da3249",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Symmetric difference between set1 and set2: {1, 2, 3, 6, 7, 8}\n"
     ]
    }
   ],
   "source": [
    "symmetric_difference_set = set1 ^ set2\n",
    "print(\"Symmetric difference between set1 and set2:\", symmetric_difference_set)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
